package main

import (
	"encoding/json"

	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models/trans/refunds"
	servicerefunds "jlpay-sdk-go/pkg/jlpay/services/trans/refunds"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 构建退款查询请求
func buildRefundsQueryRequest() *refunds.RefundsQueryRequest {
	request := refunds.NewRefundsQueryRequest()

	// 设置请求参数
	request.SetMchID("849581183510017")
	//request.SetTransactionID("451147688260420350771289")
	request.SetOutTradeNo("0c12656513f74a8f")

	return request
}

// 退款查询示例
func refundsQueryDemo(refundsQueryService *servicerefunds.RefundsQueryService) {
	// 创建退款查询请求
	request := buildRefundsQueryRequest()

	// 序列化请求数据并打印
	requestMap, _ := request.ToMap()
	requestJSON, _ := json.Marshal(requestMap)
	utils.Debugf("退款查询请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := refundsQueryService.RefundsQuery(request)
	if err != nil {
		utils.Errorf("退款查询请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("退款查询")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 退款查询示例 开始 =====")
	utils.Info("=============================")

	// 创建配置对象和退款查询服务
	config := demo.CreateDemoConfig()
	refundsQueryService := servicerefunds.NewRefundsQueryService(config)

	refundsQueryDemo(refundsQueryService)

	utils.Info("=============================")
	utils.Info("===== 退款查询示例执行完毕 =====")
	utils.Info("=============================")
}
